package com.example.mapper;

import com.example.entity.Sport;
import com.example.entity.WxRun;
import com.github.pagehelper.Page;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * TODO
 *
 * @Comment：最难的一次作业
 * @Date: 2023/12/10
 */
public interface SportMapper {

    /**
     * 添加
     */
    @Insert("insert into sport(title, content, create_time, create_name) values (#{title}, #{content}, #{createTime}, #{createName})")
    void insert(Sport sport);

    /**
     * 删除
     */
    void delete(Long id);

    /**
     * 修改
     */
    void update(Sport sport);

    /**
     * 分页查询
     */
    Page<Sport> findPage(String queryString);

    /**
     * 查询详情
     * */
    Sport findInfo(Long id);

    /**
     * 存储微信运动步数
     * */
    void insertStep(@Param("runs") List<WxRun> runs);

    /**
     * 根据时间查询对应的微信步数
     * */
    @Select("select * from wx_run where openid=#{openid} and time=#{time}")
    WxRun findStepByTime(@Param("openid") String openid, @Param("time") String time);

    @Update("update wx_run set step=#{step} where openid=#{openid} and time=#{time}")
    void updateStep(@Param("openid") String openid, @Param("time") String time, @Param("step") Integer step);

    @Select("select * from wx_run where openid=#{openid} and (time<=#{beginTime} and time>=#{endTime})")
    List<WxRun> findByTime(@Param("beginTime") String dateTime, @Param("endTime") String date1, @Param("openid") String openId);
}
